<?php  
function rndStr(){
    $string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $len = rand(0,3)+5;
    $rst = '';
    $strl = strlen($string);
    for($i=0;$i<$len;$i++){
        $ind = rand(0, $strl);
        $s = $string[$ind];
        $rst .= $s;
    }
    return $rst;
}

$name = time() . rndStr(); 

$type = $_POST['datatype'];

if($type == 'img'){
	$img = str_replace(' ', '+', $_POST['dataimg']);
	$img = base64_decode($img);
	$f = fopen('upfile/' . $name . '.jpg', 'w+');
	fwrite($f, $img);
	fclose($f);
	echo 'upfile/' . $name . '.jpg';
}
}
?> 